package genetic.operators;

import java.util.Random;

import genetic.interfaces.Crossover;
import genetic.interfaces.Individual;

public class CrossoverUniform<I extends Individual<Integer,?>> implements Crossover<I> {

	@Override
	public I crossover(I father, I mother) {
		Random rand = new Random();
		@SuppressWarnings("unchecked")
		I child = (I) father.copy();
		
		for(int i = 0; i < child.getNumberOfGenes(); i++){
			int gene = (rand.nextDouble() > 0.5) ? mother.getGene(i) : father.getGene(i);
			child.setGene(i, gene);
		}
		
		return child;
	}

}
